import 'package:flutter/material.dart';
import 'package:flutter_demo/core/common/model/ui_element_model.dart';
import 'package:flutter_demo/core/common/utils/image_utils.dart';
import 'package:flutter_demo/core/common/values/constants.dart';
import 'package:flutter_demo/core/common/values/gaps.dart';
import 'package:flutter_demo/core/common/values/server.dart';
import 'package:flutter_demo/core/route/app_routes.dart';
import 'package:flutter_demo/core/typeof/function.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

/**
 * 自定义通用按钮
 */
Widget elementButtonWidget(ElementButton? elementButton,
    {ParamVoidCallback? onPressed}) {
  if (elementButton == null) return Gaps.empty;
  final theme = Get.theme;
  return MaterialButton(
    onPressed: () {
      if (onPressed == null) {
        logger.i("通用按钮被点击了");
        //RouteUtils.routeFromActionStr(elementButton.action);
      } else {
        onPressed.call();
      }
    },
    height: 24.h,
    color: Colors.transparent,
    //按钮点击下的颜色
    highlightColor: theme.hintColor,

    //按钮的阴影
    elevation: 0,
    padding: const EdgeInsets.all(0),
    minWidth: 40.h,
    focusElevation: 0,

    ///按钮按下时的阴影高度
    highlightElevation: 0,

    ///用来设置按钮的边框的样式
    shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.r),
        side: BorderSide(
          color: theme.hintColor,
        )),
    child: Row(children: [
      Gaps.hGap12,
      if (elementButton.actionType == "client_customized")
        Image.asset(ImageUtils.getImagePath('icon_play_small'),
            color: theme.iconTheme.color, width: 12.w, height: 12.h),

      Text(
        elementButton.text.toString(),
        style: TextStyle(fontSize: 12.sp, color: theme.iconTheme.color),
      ),

      //app 内部跳转用 more
      if (elementButton.actionType == APP_ROUTER_TAG)
        Image.asset(ImageUtils.getImagePath('icon_more'),
            color: theme.iconTheme.color, width: 12.h, height: 12.h),
      Gaps.hGap10,
    ]),
  );
}
